<?php
header("Content-type:text/html;charset=utf-8");
$dsn = "mysql:host=localhost;dbname=hdc50";
$username="root";
$password = "";
try{
	$pdo = new Pdo($dsn,$username,$password);
}catch(PDOException $e) {
	die($e->getMessage());
}
$pdo->query("set names utf8");
$data= [
	'name'=>'小鹏','1998-3-8','sex'=>1
];
try {
    $sql = "insert into stu(username,age,sex) values(?,?,?)";
    $state = $pdo->prepare($sql);
    $id=0;
    foreach($data as $key=>$value)
    {   
        // print_r($data);exit;
    	$style = is_numeric($value)?PDO::PARAM_INT:PDO::PARAM_STR;
    	$$key=$value;
        // print_r($value);
    	$state->bindParam(++$id,$$key,$style);

    }
    $row = $state->execute();
    // print_r($row);
    // var_dump($row);
} catch (PDOException $e) {
    $e->getMessage();
}